package org.testmyapp.entities;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.testmyapp.DateUtil;
import org.testmyapp.persistence.BusinessObjectMarker;

@Entity
@Table(name = "BILL")
@IdClass(BillPk.class)
public class Bill extends AbsProcessRelatedObject implements
		BusinessObjectMarker {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2644096443724027843L;

	public static String tableName = "Bill";

	@Temporal(value = TemporalType.DATE)
	private Date startDate;
	@Temporal(value = TemporalType.DATE)
	private Date endDate;
	@Temporal(value = TemporalType.DATE)
	private Date entryDate;
	private Integer billSum;
	private String careProvider;
	@Id
	@ManyToOne(cascade=CascadeType.ALL)
	@JoinColumn(name = "accountingMedical_fk")
	private AccountingMedical accountingMedical;
	@Id
	private Integer billNr;
	@ManyToOne
	@JoinColumns({
			@JoinColumn(name = "ip_contract_fk", referencedColumnName = "contract_id_fk"),
			@JoinColumn(name = "ip_person_fk", referencedColumnName = "person_id_fk") })
	private InsuredPerson ip;
	@Column(nullable = true)
	private String careProviderType;

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Date getEntryDate() {
		return entryDate;
	}

	public void setEntryDate(Date entryDate) {
		this.entryDate = entryDate;
	}

	public Integer getBillSum() {
		return billSum;
	}

	public void setBillSum(Integer billSum) {
		this.billSum = billSum;
	}

	public String getCareProvider() {
		return careProvider;
	}

	public void setCareProvider(String careProvider) {
		this.careProvider = careProvider;
	}

	public AccountingMedical getAccountingMedical() {
		return accountingMedical;
	}

	public void setAccountingMedical(AccountingMedical accountingMedical) {
		this.accountingMedical = accountingMedical;
	}

	public Integer getBillNr() {
		return billNr;
	}

	public void setBillNr(Integer billNr) {
		this.billNr = billNr;
	}

	public InsuredPerson getIp() {
		return ip;
	}

	public void setIp(InsuredPerson ip) {
		this.ip = ip;
	}

	@Override
	public String toString() {
		return "Rechnung: " + billNr + ", VP: " + ip + ", start: "
				+ DateUtil.dateToStringNoTime(startDate, ".") + ", ende: "
				+ DateUtil.dateToStringNoTime(endDate, ".") + ", eingang: "
				+ DateUtil.dateToStringNoTime(entryDate, ".") + ", betrag: "
				+ billSum;
	}

	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (!(o instanceof Bill) || o == null)
			return false;
		Bill other = (Bill) o;
		if ((this.getAccountingMedical() == null && other
				.getAccountingMedical() != null)
				|| (!this.getAccountingMedical().equals(
						other.getAccountingMedical()))) {
			return false;
		}
		if ((this.getBillNr() == null && other.getBillNr() != null)
				|| !this.getBillNr().equals(other.getBillNr())) {
			return false;
		}
		if ((this.getIp() == null && other.getIp() != null)
				|| !this.getIp().equals(other.getIp())) {
			return false;
		}
		if ((this.getCareProvider() == null && other.getCareProvider() != null)
				|| !this.getCareProvider().equals(other.getCareProvider())) {
			return false;
		}
		if ((this.getStartDate() == null && other.getStartDate() != null)
				|| !this.getStartDate().equals(other.getStartDate())) {
			return false;
		}
		if ((this.getEntryDate() == null && other.getEntryDate() != null)
				|| !this.getEntryDate().equals(other.getEntryDate())) {
			return false;
		}
		if ((this.getEndDate() == null && other.getEndDate() != null)
				|| !this.getEndDate().equals(other.getEndDate())) {
			return false;
		}
//		if (!(this.getProcessInstanceId() == null && other
//				.getProcessInstanceId() == null)
//				|| !this.getProcessInstanceId().equals(
//						other.getProcessInstanceId())) {
//			return false;
//		}
		return true;
	}

}
